<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:business:edit']"
        >审核</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="businessList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="商户ID" align="center" prop="id" />
      <el-table-column label="商户名称" align="center" prop="name" />
      <el-table-column label="法人" align="center" prop="corporation" />
      <el-table-column label="地址" align="center">
        <template slot-scope="scope">
          {{scope.row.provinceName}}{{scope.row.cityName}}{{scope.row.countyName}}
        </template>
      </el-table-column>
      <el-table-column label="类型" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.type==0">公司化公寓</span>
          <span v-if="scope.row.type==1">个人职业房东</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.status==1">审核通过</span>
          <span v-if="scope.row.status==2">审核不通过</span>
          <span v-if="scope.row.status==3">待审核</span>
        </template>
      </el-table-column>
      <el-table-column label="管理员" align="center" prop="userName" />
      <el-table-column label="申请时间" align="center" prop="createTime" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改商户对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="商户名称" prop="name">
          <el-input v-model="form.name" disabled />
        </el-form-item>
        <el-form-item label="法人" prop="corporation">
          <el-input v-model="form.corporation" disabled/>
        </el-form-item>
        <el-form-item label="省" prop="provinceName">
          <el-input v-model="form.provinceName" disabled/>
        </el-form-item>
        <el-form-item label="市" prop="cityName">
          <el-input v-model="form.cityName" disabled/>
        </el-form-item>
        <el-form-item label="区" prop="countyName">
          <el-input v-model="form.countyName" disabled/>
        </el-form-item>
        <el-form-item label="详细地址" prop="address">
          <el-input v-model="form.address" disabled/>
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-input v-model="form.status==1?'审核通过':form.status==2?'未审核':'审核未通过'" disabled/>
        </el-form-item>
        <el-form-item label="管理员" prop="userName">
          <el-input v-model="form.userName" disabled/>
        </el-form-item>
        <el-form-item label="统一信征码" prop="zheng">
          <el-input v-model="form.zheng" disabled/>
        </el-form-item>
        <el-form-item label="营业执照" prop="type">
          <el-image
            style="width: 100px; height: 100px"
            src=""
            fit="fit" disabled></el-image>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm(form.id)">通过</el-button>
        <el-button type="primary" @click="notUpdate(form.id)">不通过</el-button>
        <el-button @click="cancel">返回</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listBusiness, getBusiness, delBusiness, update, updateBusiness} from "@/api/system/business";

export default {
  name: "Business",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商户表格数据
      businessList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        corporation: null,
        province: null,
        city: null,
        county: null,
        address: null,
        type: null,
        status: null,
        userId: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        url: null,
        zheng: null,
        headPicture: null,
        legalPersonName: null,
        certNum: null,
        certPicture: null,
        certPicture2: null,
        certPicture3: null,
        brandName: null,
        apartmentUrl: null,
        serviceHotline: null
      },
      // 表单参数
      form: {},
      businessDTO:{},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询商户列表 */
    getList() {
      this.loading = true;
      listBusiness(this.queryParams).then(response => {
        console.log(response.rows);
        this.businessList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        corporation: null,
        province: null,
        city: null,
        county: null,
        address: null,
        type: null,
        status: 0,
        userId: null,
        createTime: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        url: null,
        zheng: null,
        headPicture: null,
        legalPersonName: null,
        certNum: null,
        certPicture: null,
        certPicture2: null,
        certPicture3: null,
        brandName: null,
        apartmentUrl: null,
        serviceHotline: null
      };
      this.resetForm("form");
    },
    notUpdate(id){
      this.businessDTO.id=id;
      updateBusiness(this.businessDTO).then(response=>{
        if(response.code==200){
          this.open=false;
          this.$message.success("操作成功");
          this.getList();
        }
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 审核 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getBusiness(id).then(response => {
        console.log("审核信息::",response.data);
        this.form = response.data;
        this.open = true;
        this.title = "修改商户";
      });
    },
    /** 提交按钮 */
    submitForm(id) {
      this.businessDTO.id=id;
      update(this.businessDTO).then(response=>{
        if(response.code==200){
          this.open=false;
          this.$message.success("操作成功");
          this.getList();
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除商户编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delBusiness(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/business/export', {
        ...this.queryParams
      }, `system_business.xlsx`)
    }
  }
};
</script>
